const gulp = require('gulp');
const server = require('karma').Server;
const webpack = require('webpack-stream');

let protoFiles = "./src/main/pb/b3.proto";
let distDir = "./src/main/pb/"
var gulpprotobuf = require('gulp-protobufjs');
let protobuf = require("gulp-protobuf");
let jasmine = require('gulp-jasmine-livereload-task');

gulp.task("pb", () => {
    return gulp.src(protoFiles)
    .pipe(protobuf.pbjs({
        target: "static-module",
        wrap: "commonjs"
    }))
    .pipe(gulp.dest(distDir));
});

const BROWSER_SOURCES = [
    'src/**/*.js'
];

gulp.task('build', function() {
    return gulp.src(BROWSER_SOURCES, {base: '.'})
        .pipe(webpack({
            module: {
                loaders: [{
                    test: /\.js$/,
                    loader: 'babel-loader',
                    exclude: /node_modules/,
                    query: {
                        presets: ['es2015']
                    }
                }]
            },
            output: {
                filename: 'web.js'
            }
        }))
        .pipe(gulp.dest('dist/'));
});

gulp.task('test',['build'], jasmine({
    files: ['dist/web.js']
}));

gulp.task('karma', function (done) {
    new server({
      configFile: __dirname + '/karma.conf.js',
      singleRun: false
    }, done).start();
  });